//
//  HMTabBar.swift
//  Weibo
//
//  Created by 吴少飞 on 16/9/19.
//  Copyright © 2016年 wushaofei. All rights reserved.
//

import UIKit



class HMTabBar: UITabBar {
    
    private lazy var composeButton:UIButton =  {
        
        let button = UIButton()
        
        //设置按钮普通和高亮图片
        button.setImage(UIImage(named:"tabbar_compose_icon_add"), for: .normal)
        button.setImage(UIImage(named:"tabbar_compose_icon_add_highlighted"), for: .highlighted)
        
        //设置按钮的背景图片
        button.setBackgroundImage(UIImage(named:"tabbar_compose_button"), for: .normal)
        button.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), for: .highlighted)
        
        button.sizeToFit()
        
        return button
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        addSubview(composeButton)
        
    }
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        //设置按钮中心点
        composeButton.centerX = frame.width/2
        composeButton.centerY = frame.height/2
        //每个item宽
        let width = frame.width/5
        
        var index = 0
        
        for value in subviews {
            
            if value.isKind(of: NSClassFromString("UITabBarButton")!) {
                
                value.width = width
                value.x = CGFloat(index) * width
                
                index += 1
                if index == 2 {
                    
                    index += 1
                }
                
            }
            
            
        }
        
    }
    
    
}
